package cn.stylefeng.guns.modular.yy.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.yy.entity.CourseHistory;
import cn.stylefeng.guns.modular.yy.mapper.CourseHistoryMapper;
import  cn.stylefeng.guns.modular.yy.service.CourseHistoryService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 唐元鹏
 * @since 2021-02-24
 */
@Service
public class CourseHistoryServiceImpl extends ServiceImpl<CourseHistoryMapper, CourseHistory> implements CourseHistoryService {

    @Override
    public void add(CourseHistory param){
        CourseHistory entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(CourseHistory param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(CourseHistory param){
        CourseHistory oldEntity = getOldEntity(param);
        CourseHistory newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public CourseHistory findBySpec(CourseHistory param){
        return null;
    }

    @Override
    public List<CourseHistory> findListBySpec(CourseHistory param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(CourseHistory param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(CourseHistory param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private CourseHistory getOldEntity(CourseHistory param) {
        return this.getById(getKey(param));
    }

    private CourseHistory getEntity(CourseHistory param) {
        CourseHistory entity = new CourseHistory();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
